<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="<c:url value='/css/Pub.css'/>"></link>
    <script type="text/javascript">
        var path = "${pageContext.request.contextPath}/";
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!-- 如果出现没有效果的情况直接检查是否是因为路径的问题 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css"
          type="text/css"></link>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/easyui/themes/icon.css" type="text/css"></link>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<p>以下是图书的所有分类：</p>
<table class="easyui-datagrid" style="width:400px;height:250px"
       data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true">
    <thead align="center">
    <tr>
        <th data-options="field:'code',width:100,align:'center'">分类名称</th>
        <th data-options="field:'name',width:100,align:'center'">说明</th>
        <th data-options="field:'price',width:100,align:'center'">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${requestScope.types}" var="type" varStatus="idx">
        <tr <c:if test="${idx.count%2==0}">class="even"</c:if>>
            <td>
                    ${type.name}
            </td>
            <td>
                    ${type.descr}
            </td>
            <td>
                <a class="easyui-linkbutton" data-options="iconCls:'icon-remove'"
                   onclick="_delete('${type.id}');">删除</a>
            </td>
        </tr>
    </c:forEach>
    <tr style="background:#E0E0E0;">
        <td></td>
        <td></td>
        <td colspan="3">
            <button class="OperBtn" onclick="sure();" style="width:120px;">添加一个分类</button>
        </td>
    </tr>
    </tbody>
</table>
</body>
<script type="text/javascript">
    function sure() {
        var url = path + "jsp/admin/type/add.jsp";
        window.open(url, "_blank", "width=410px;height=300px;");
    }

    // 删除分类
    function _delete(id) {
        var url = "${pageContext.request.contextPath}/admin/type?action=deleteTypes&id=" + id;
        window.location.href = url;
    }
</script>
</html>
